package com.handpay.nocardpay.baselibrary.setting.presenter;

import android.content.Context;

import com.handpay.nocardpay.baselibrary.account.model.ILogOutModel;
import com.handpay.nocardpay.baselibrary.account.model.impl.UserLogOutModelImpl;
import com.handpay.nocardpay.baselibrary.account.view.ILogoutView;
import com.handpay.nocardpay.baselibrary.commbase.model.IBaseModel;
import com.handpay.nocardpay.baselibrary.commbase.model.bean.BaseErrorInfo;
import com.handpay.nocardpay.baselibrary.commbase.model.bean.BaseResponseBean;
import com.handpay.nocardpay.baselibrary.commbase.presenter.IBasePresenter;

import java.util.HashMap;

/**
 * Created by sxshi on 2017/8/18.
 */

public class SettingPresenterImpl implements IBasePresenter {
    private ILogoutView logoutView;
    private Context mContext;
    private ILogOutModel<BaseResponseBean> logOutModel;

    public SettingPresenterImpl(Context mContext) {
        this.mContext = mContext;
        logOutModel = new UserLogOutModelImpl(mContext);
    }

    public void setLogoutView(ILogoutView logoutView) {
        this.logoutView = logoutView;
    }

    public void userLogOut(HashMap<String, Object> paramers, boolean isLoading) {
        if (logoutView != null) {
            if (isLoading) {
                logoutView.showProgress();
            }
        }
        logOutModel.userLogOut(paramers, BaseResponseBean.class, new IBaseModel.OnRequestFinishedListener<BaseResponseBean>() {
            @Override
            public void onError(BaseErrorInfo baseErrorInfo) {
                if (logoutView != null) {
                    logoutView.hideProgress();
                    logoutView.showErrorAlert(baseErrorInfo);
                }
            }

            @Override
            public void onSuccess(BaseResponseBean response) {
                if (logoutView != null) {
                    logoutView.hideProgress();
                    logoutView.logOutSuccess();
                }
            }
        });
    }

    @Override
    public void onDestory() {
        if (logoutView!=null){
            logoutView=null;
        }
    }
}
